package com.HAPOERP.managedBean;


import java.io.IOException;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import com.HAPOERP_EJB.persistance.User;
import com.hapoerpejb.services.UserDaoLocal;

@ManagedBean(name="LoginManaged")
@SessionScoped
public class LoginManaged {
@EJB
UserDaoLocal localuser;
private User usr;
int r;

	public String verifLogin()
	{
		 r =localuser.findByUserAndPwd(getUsr().getLogin(), getUsr().getPwd());
		 	
			System.out.println("valeur du role: "+r);
			try {
				
				switch (r) {
				case 1 ://manager
					FacesContext.getCurrentInstance().getExternalContext().redirect("manager.faces");
					break;
				case 2 :// maker
					FacesContext.getCurrentInstance().getExternalContext().redirect("Makers.faces");
					break;
				case 3 ://Dot
					break;
				case 4 : //dhr
					break;
				default:FacesContext.getCurrentInstance().getExternalContext().redirect("index.faces");
					break;
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return "";
	}
	
	
	
	public User getUsr() {
		if(usr==null)
			usr=new User();
		return usr;
	}
	public void setUsr(User usr) {
		this.usr = usr;
	}


}
